package com.tz.dream.architect.mvp.list.demo;

import com.tz.dream.architect.mvp.R;
import com.tz.dream.architect.mvp.framework.lce.MvpLceView;
import com.tz.dream.architect.mvp.framework.lce.impl.fragment.BaseRefreshLceFragment;
import com.tz.dream.architect.mvp.list.base.adapter.BaseRefreshAdapter;
import com.tz.dream.architect.mvp.list.demo.adapter.EssenceAdapter;
import com.tz.dream.architect.mvp.list.demo.bean.PostModel;

/**
 * 作者: Dream on 2018/3/23 21:38
 * QQ:510278658
 * E-mail:510278658@qq.com
 */

public class MyListFragment extends
        BaseRefreshLceFragment<PostModel, MvpLceView<PostModel>, MyListPresenter>
        implements MvpLceView<PostModel> {

    //配置P层
    @Override
    public MyListPresenter createPresenter() {
        return new MyListPresenter(getActivity());
    }

    //配置布局文件
    @Override
    public int getContentView() {
        return R.layout.fragment_essence;
    }

    //初始化界面
    @Override
    public void initData() {
        loadData(false);
        setLceAnimator(new LoadingAnimator());
    }

    //配置Adapter
    @Override
    public BaseRefreshAdapter bindAdapter() {
        return new EssenceAdapter(getActivity());
    }

    //刷新数据->下拉刷新
    @Override
    public void refreshData(boolean isDownRefresh) {
        super.refreshData(isDownRefresh);
        loadData(true);
    }

    //绑定数据
    @Override
    public void bindData(PostModel model) {
        //super作用：框架内部封装了下拉刷新头部和上拉加载底部隐藏和显示逻辑(每一个功能模块都是重复)
        super.bindData(model);
        //6、更新Adapter->核心：更新ArrayList列表
        getAdapter().refreshAdapter(isDownRefresh(),model.getList(),model);
    }

    //加载数据
    @Override
    public void loadData(boolean pullToRefresh) {
        super.loadData(pullToRefresh);
        getPresenter().getEssenceList(EssenceAdapter.Type.Text.type, pullToRefresh);
    }

}
